package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.aspect.operate.OperateLog;
import com.cskaoyan.wordmemorize.common.aspect.operate.OperateLogConstant;
import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.LevelDTO;
import com.cskaoyan.wordmemorize.dto.admin.LevelPrivilegeDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.*;
import com.cskaoyan.wordmemorize.service.LevelPrivilegeService;
import com.cskaoyan.wordmemorize.service.LevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/privilege")
public class AdminPrivilegeController {

    @Autowired
    LevelPrivilegeService  levelPrivilegeService;
    @SaAdminCheckPermission("admin:privilege:add")
    @PostMapping("")
    public Result addLevelPrivilege(@RequestBody LevelPrivilegeCommand  command)
    {
        levelPrivilegeService.addLevelPrivilege( command);
        return Result.ok();
    }
    @SaAdminCheckPermission("admin:privilege:update")
    @PutMapping("")
    public Result updateLevelPrivilege(@RequestBody LevelPrivilegeCommand  command)
    {
        levelPrivilegeService.updateLevelPrivilege( command);
        return Result.ok();
    }
    @SaAdminCheckPermission("admin:privilege:search")
    @GetMapping("list")
    public Result<PageDTO<LevelPrivilegeDTO>> getLevelPrivilegeList(LevelPrivilegePageRequest pageRequest)
    {
        PageDTO<LevelPrivilegeDTO> levelList = levelPrivilegeService.getLevelPrivilegeList(pageRequest);
        return Result.ok(levelList);
    }

    @SaAdminCheckPermission("admin:privilege:delete")
    @DeleteMapping("{id}")
    public Result deleteLevelPrivilege(@PathVariable Long id)
    {
        levelPrivilegeService.deleteLevelPrivilege( id);
        return Result.ok();
    }
    @SaAdminCheckPermission("admin:privilege:batchdelete")
    @DeleteMapping("batch")
    public Result deleteLevels(@RequestBody BatchDeleteCommand command)
        {
            levelPrivilegeService.batchDeleteLevelPrivilege( command);
            return Result.ok();
        }

}
